package com.yanqu.road.server.cmd.skinvolume;

import com.yanqu.road.pb.skinvolume.SkinVolumeProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.SkinVolumeModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

/**
 * @author ：zfr
 * @date ：2021/4/27 18:57
 */
@Cmd(code = GameProtocol.S_SKIN_VOLUME_GET_REWARD, desc = "霓裳卷领奖")
public class SkinVolumeGetRewardCmd extends AbstractCommand {
    private int volumeId;
    private int index;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        SkinVolumeProto.GetRewardReqMsg reqMsg = SkinVolumeProto.GetRewardReqMsg.parseFrom(packet.getBytes());
        volumeId = reqMsg.getVolumeId();
        index = reqMsg.getIndex();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = player.getModule(SkinVolumeModule.class).getReward(volumeId, index);
        if (ret != 0) {
            SkinVolumeProto.GetRewardRespMsg.Builder respMsg = SkinVolumeProto.GetRewardRespMsg.newBuilder();
            respMsg.setRet(ret);
            player.sendPacket(ClientProtocol.U_SKIN_VOLUME_GET_REWARD, respMsg);
        }
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
